package com.heyidlebooks.mgr;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.log4j.Logger;


public class DatabaseConnectionMgr {

	private static final Logger LOG = Logger
			.getLogger(DatabaseConnectionMgr.class);

	public static Connection getConnection() {
		Connection myConnection = null;
		try {
			// create driver - ALTER TO SUIT YOUR DRIVER/ DBMS
			Class.forName("com.mysql.jdbc.Driver").newInstance();

			// database connection code - ENTER YOUR DETAILS
			String username = "root";
			String password = "";

			// URL - ALTER TO CONNECT TO YOUR DATABASE
			String dbURL = "jdbc:mysql://localhost/heyidleb_db1?user="
					+ username + "&password=" + password + "&characterEncoding=utf8";

			// create the connection - ALTER FOR YOUR DBMS
			myConnection = DriverManager
					.getConnection(dbURL);

		} catch (SQLException e) {
			LOG.error(e);
		} catch (InstantiationException e) {
			LOG.error(e);
		} catch (IllegalAccessException e) {
			LOG.error(e);
		} catch (ClassNotFoundException e) {
			LOG.error(e);
		}
		return myConnection;
	}
}
